package game.module.announce.processor;

import java.util.Collection;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import game.common.PlayingRoleMsgProcessor;
import game.entity.PlayingRole;
import game.module.announce.bean.AnnounceBean;
import game.module.announce.dao.AnnounceCache;
import lion.common.MsgCodeAnn;
import lion.netty4.message.MyRequestMessage;
import lion.netty4.message.RequestMessageRaw;
import lion.netty4.message.RequestProtoMessage;
import lua.LuaMessageHall.AnnounceEntity;
import lua.LuaMessageHall.C2SAnnounceList;
import lua.LuaMessageHall.S2CAnnounceList;

@MsgCodeAnn(msgcode = C2SAnnounceList.id, accessLimit = 500)
public class AnnounceListProcessor extends PlayingRoleMsgProcessor {

	private static Logger logger = LoggerFactory.getLogger(AnnounceListProcessor.class);

	@Override
	public void process(PlayingRole playingRole, RequestMessageRaw requestMessage) throws Exception {
		logger.info("announce list!");
		S2CAnnounceList respMsg = new S2CAnnounceList();
		Collection<AnnounceBean> announceAll = AnnounceCache.getInstance().getAnnounceAll();
		respMsg.list = new AnnounceEntity[announceAll.size()];
		int aIndex = 0;
		for (AnnounceBean announceBean : announceAll) {
			respMsg.list[aIndex++] = new AnnounceEntity(announceBean.getTitle(), announceBean.getContent());
		}
		// ret
		playingRole.writeAndFlush(respMsg.build(playingRole.alloc()));
	}

	@Override
	public void processProto(PlayingRole playingRole, RequestProtoMessage request) throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	public void processWebsocket(PlayingRole playingRole, MyRequestMessage request) throws Exception {

	}

}
